/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dnbW.entityW;

/**
 *
 * @author truongbaquan
 */
public class Operator {
    public enum OperatorType {Equal, Unequal, LessThan, LessThanOrEqual,
                                MoreThan, MoreThanOrEqual, Contain};

    private OperatorType type;

    public OperatorType getType() {
        return type;
    }

    public Operator(OperatorType type) {
        this.type = type;
    }

    public String getSQLString() {
        switch (this.type) {
            case Equal: return "LIKE";
            case Unequal: return "NOT LIKE";
            case LessThan: return "<";
            case LessThanOrEqual: return "<=";
            case MoreThan: return ">";
            case MoreThanOrEqual: return ">=";
            case Contain: return "LIKE";
            default: return null;
        }
    }

    public static Operator createOperator(String opString) {
        if (opString.equals("=")) {
            return new Operator(OperatorType.Equal);
        }
        else if (opString.equals("!=")) {
            return new Operator(OperatorType.Unequal);
        }
        else if (opString.equals("<")) {
            return new Operator(OperatorType.LessThan);
        }
        else if (opString.equals("<=")) {
            return new Operator(OperatorType.LessThanOrEqual);
        }
        else if (opString.equals(">")) {
            return new Operator(OperatorType.MoreThan);
        }
        else if (opString.equals(">=")) {
            return new Operator(OperatorType.MoreThanOrEqual);
        }
        else if (opString.equals("like")) {
            return new Operator(OperatorType.Contain);
        }
        else return null;
    }
}
